﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure;

namespace LogViewApp.Web
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service2
    {
        [OperationContract]
        public void DoWork()
        {
            // Add your operation implementation here
            return;
        }
        [OperationContract]
        public List<string> GetCloudBlobList()
        {
            IEnumerable<IListBlobItem> Listblobs;
            CloudBlobContainer container;
            CloudBlobClient blobs;
            CloudStorageAccount account;
            account = Microsoft.WindowsAzure.CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
            blobs = account.CreateCloudBlobClient();
            var ContainerName = string.Format("{0}{1}{2}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            container = blobs.GetContainerReference(ContainerName);
            SharedAccessPolicy readPolicy;
            readPolicy = new SharedAccessPolicy()
            {
                Permissions = SharedAccessPermissions.Read,
                SharedAccessExpiryTime = DateTime.UtcNow + TimeSpan.FromMinutes(10)
            };
            Listblobs = container.ListBlobs(new BlobRequestOptions() { UseFlatBlobListing = true });
            var UriStringList = from CloudBlob blob in Listblobs
                                select (blob.Uri.AbsoluteUri + blob.GetSharedAccessSignature(readPolicy));
            return UriStringList.ToList<string>();
        }

        // Add more operations here and mark them with [OperationContract]
    }
}
